package b1.scenes.home
{
	import b1.conifg.*;
	import b1.controls.basic.*;
	import b1.net.*;
	import b1.players.*;
	import b1.scenes.*;
	import b1.scenes.fight.*;
	import b1.utils.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.*;
	import flash.ui.Mouse;
	import flash.utils.Timer;

	public class AnimalMessage extends Sprite
	{
		private const itemGap:int = 28;
		private var plusButtons:Array;
		private var homeAnimal:HomeAnimal;
		private var bloodNumText:TextField;
		private var vitalityNumText:TextField;
		private var intelligenceNumText:TextField;
		private var speedNumText:TextField;
		private var liveText:TextField;
		private var liveNumText:TextField;
		private var prisonText:TextField;
		private var prisonNumText:TextField;
		
		public var coolDownToClose:int;
		public var coolDownToCloseMax:int;
		private var mouseOverFlag:Boolean;
		private var timer:Timer;
		private var tip:BasicMessage;
		//各种背景
		//等级
		private var levelSprite:Sprite;
		//经验条
		private var expBar:Bar;	
		//血条
		private var healthBar:Bar;
		//体力条
		private var vitalityBar:Bar;
		//智力图标
		private var intelligenceIcon:Sprite;
		//速度图标
		private var speedIcon:Sprite;
		//原籍
		private var liveSprite:Sprite;
		
		//准备脱去的装备
		private var equipToGetOff:EquipInfo;
		//介绍装备信息
		private var tipOfEquip:Sprite;
		//介绍数字信息的组成
		private var tipOfNum:BasicMessage;
				
		//positionType: 0, 右边; 1, 左边; coolDownToClose: 秒
		public function AnimalMessage(homeAnimal:HomeAnimal, positionType:int = 0, coolDownToClose:int = 1)
		{
			super();
			this.homeAnimal = homeAnimal;
			this.coolDownToClose = coolDownToClose;
			this.coolDownToCloseMax = coolDownToClose;
			this.mouseOverFlag = false;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var animalConfig:AnimalConfig = Config.animalConfigs[animalInfo.animalIndex];
			var initX:int;
			var initY:int;
			if (positionType == 0)
			{
				initX = 60;
				initY = 20;
			}
			else
			{
				initX = -260;
				initY = 20;
			}
			this.plusButtons = new Array();
			//背景图片
			var AnimalMsgBgr:Class = ResourceHelper.getInstance().getClassByName("AnimalMsgBgr");
			var animalBgrSprite:Sprite = new AnimalMsgBgr();
			animalBgrSprite.alpha = 0.8; 
			if (positionType == 1)
			{
				animalBgrSprite.scaleX = -1;
			}
			addChild(animalBgrSprite);
			
			//名字
			var nameText:TextField = new TextField();
			nameText.selectable = false;
        	nameText.autoSize = TextFieldAutoSize.LEFT;
			nameText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0x000000, true);
			nameText.text = animalInfo.ownerName.substr(0, 4) + "的" + animalInfo.animalName;
			nameText.x = initX;
			nameText.y = initY;
			addChild(nameText);
			
			if (homeAnimal.animalId > 0)
			{
				//等级背景
				var LevelBgr:Class = ResourceHelper.getInstance().getClassByName("LevelBgr");
				levelSprite = new LevelBgr();
				levelSprite.width = 22;
				levelSprite.height = 22;
				levelSprite.x = nameText.x + nameText.width + 10;
				levelSprite.y = nameText.y + 6;
				addChild(levelSprite);
				levelSprite.addEventListener(MouseEvent.MOUSE_OVER, levelSpriteOnMouseOver);
				levelSprite.addEventListener(MouseEvent.MOUSE_OUT, tipOnMouseOut);
				//等级文字
				var levelText:TextField = new TextField();
				levelText.selectable = false;
	        	levelText.autoSize = TextFieldAutoSize.CENTER;
				levelText.defaultTextFormat = new TextFormat("微软雅黑", 16, 0x000000, true, true);
				levelText.text = " " + animalInfo.level.toString() + " ";
				levelText.x = levelSprite.x + (levelSprite.width - levelText.width) / 2 - 2;
				levelText.y = levelSprite.y + (levelSprite.height - levelText.height) / 2;
				addChild(levelText);
				levelText.mouseEnabled = false;
				//经验文字
				var expText:TextField = new TextField();
				expText.selectable = false;
	        	expText.autoSize = TextFieldAutoSize.LEFT;
				expText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
				expText.text = "经验";
				expText.x = nameText.x;
				expText.y = nameText.y + 40;
				addChild(expText);
				//经验条
				var levelConfig:LevelConfig = Config.levelConfigs[animalInfo.level - 1];
				expBar = new Bar("ExpBottomBar", "ExpTopBar", levelConfig.experience, animalInfo.experience, 70, 10);
				expBar.x = expText.x + expText.width + 5;
				expBar.y = expText.y + 8;
				addChild(expBar);
				expBar.addEventListener(MouseEvent.MOUSE_OVER, expBarOnMouseOver);
				expBar.addEventListener(MouseEvent.MOUSE_OUT, tipOnMouseOut);
				//经验数字
				var expNumText:TextField = new TextField();
				expNumText.selectable = false;
	        	expNumText.autoSize = TextFieldAutoSize.LEFT;
				expNumText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
				expNumText.text = animalInfo.experience.toString() + "/" + levelConfig.experience.toString();
				expNumText.x = expBar.x + expBar.width + 10;
				expNumText.y = expText.y;
				addChild(expNumText);
			}
			else if (homeAnimal.animalId < 0)
			{
				//掉落装备文字
				var equipDropText:TextField = new TextField();
				equipDropText.selectable = false;
	        	equipDropText.autoSize = TextFieldAutoSize.LEFT;
				equipDropText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
				equipDropText.text = "掉落";
				equipDropText.x = nameText.x;
				equipDropText.y = nameText.y + 40;
				addChild(equipDropText);
				//装备图标
				var posX:int = equipDropText.x + equipDropText.width + 8
				var posY:int = equipDropText.y + 5;
				addEquipDropIcon((animalInfo as VirtualAnimalConfig).armsDropPossibility, posX, posY);
			}
			
			//血量文字
			var bloodText:TextField = new TextField();
			bloodText.selectable = false;
        	bloodText.autoSize = TextFieldAutoSize.LEFT;
			bloodText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			bloodText.text = "生命";
			bloodText.x = nameText.x;
			bloodText.y = nameText.y + 40 + itemGap;
			addChild(bloodText);
			//血条
			healthBar = new Bar("BloodButtomBar", "BloodTopBar", animalInfo.healthPointMax, animalInfo.currentHealthPoint, 70, 10);
			healthBar.x = bloodText.x + bloodText.width + 5;
			healthBar.y = bloodText.y + 8;
			addChild(healthBar);
			healthBar.addEventListener(MouseEvent.MOUSE_OVER, healthBarOnMouseOver);
			healthBar.addEventListener(MouseEvent.MOUSE_OUT, tipOnMouseOut);
			//血量数字
			bloodNumText = new TextField();
			bloodNumText.selectable = false;
        	bloodNumText.autoSize = TextFieldAutoSize.LEFT;
			bloodNumText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			bloodNumText.text = animalInfo.currentHealthPoint.toString() + "/" + animalInfo.healthPointMax.toString();
			bloodNumText.x = healthBar.x + healthBar.width + 10;
			bloodNumText.y = bloodText.y;
			addChild(bloodNumText);
			bloodNumText.addEventListener(MouseEvent.MOUSE_OVER, onBloodNumTextMouseOver);
			bloodNumText.addEventListener(MouseEvent.MOUSE_OUT, onTipOfNumMouseOut);
			
			//加技能按钮
			var plusButton:PlusButton;
			if (animalInfo.skillPoint > 0 && PlayerInfoHelper.getInstance().userId == animalInfo.ownerId)
			{
				plusButton = new PlusButton(plusButtons.length, animalConfig.healthPointsPerSkillPoint, "生命");
				plusButton.width = 10;
				plusButton.height = 10;
				plusButton.x = bloodNumText.x + bloodNumText.width + 10;
				plusButton.y = healthBar.y;
				addChild(plusButton);
				plusButtons.push(plusButton);
				plusButton.addEventListener(MouseEvent.CLICK, onPlusButtonClick);
			}
			
			//体力文字
			var vitalityText:TextField = new TextField();
			vitalityText.selectable = false;
        	vitalityText.autoSize = TextFieldAutoSize.LEFT;
			vitalityText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			vitalityText.text = "体力";
			vitalityText.x = bloodText.x;
			vitalityText.y = bloodText.y + itemGap;
			addChild(vitalityText);
			//体力
			vitalityBar = new Bar("LifeButtomBar", "LifeTopBar", animalInfo.vitalityPointMax, animalInfo.currentVitalityPoint, 70, 9);
			vitalityBar.x = healthBar.x;
			vitalityBar.y = healthBar.y + itemGap;
			addChild(vitalityBar);
			vitalityBar.addEventListener(MouseEvent.MOUSE_OVER, vitalityBarOnMouseOver);
			vitalityBar.addEventListener(MouseEvent.MOUSE_OUT, tipOnMouseOut);
			//体力数字
			vitalityNumText = new TextField();
			vitalityNumText.selectable = false;
        	vitalityNumText.autoSize = TextFieldAutoSize.LEFT;
			vitalityNumText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			vitalityNumText.text = animalInfo.currentVitalityPoint.toString() + "/" + animalInfo.vitalityPointMax.toString();
			vitalityNumText.x = bloodNumText.x;
			vitalityNumText.y = bloodNumText.y + itemGap;
			addChild(vitalityNumText);
			vitalityNumText.addEventListener(MouseEvent.MOUSE_OVER, onVitalityNumTextMouseOver);
			vitalityNumText.addEventListener(MouseEvent.MOUSE_OUT, onTipOfNumMouseOut);
			//加技能按钮
			if (animalInfo.skillPoint > 0 && PlayerInfoHelper.getInstance().userId == animalInfo.ownerId)
			{
				plusButton = new PlusButton(plusButtons.length, animalConfig.vitalityPointsPerSkillPoint, "体力");
				plusButton.width = 10;
				plusButton.height = 10;
				plusButton.x = vitalityNumText.x + vitalityNumText.width + 10;
				plusButton.y = vitalityBar.y;
				addChild(plusButton);
				plusButtons.push(plusButton);
				plusButton.addEventListener(MouseEvent.CLICK, onPlusButtonClick);
			}
			
			//智力文字
			var intelligenceText:TextField = new TextField();
			intelligenceText.selectable = false;
        	intelligenceText.autoSize = TextFieldAutoSize.LEFT;
			intelligenceText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			intelligenceText.text = "智力";
			intelligenceText.x = vitalityText.x;
			intelligenceText.y = vitalityText.y + itemGap;
			addChild(intelligenceText);
			//智力图标
			var IntelligenceIcon:Class = ResourceHelper.getInstance().getClassByName("IntelligenceIcon");
			intelligenceIcon = new IntelligenceIcon();
			intelligenceIcon.width = 20;
			intelligenceIcon.height = 20;
			intelligenceIcon.x = vitalityBar.x;
			intelligenceIcon.y = intelligenceText.y + (intelligenceText.height - intelligenceIcon.height) / 2;
			addChild(intelligenceIcon);
			intelligenceIcon.addEventListener(MouseEvent.MOUSE_OVER, intelligenceIconOnMouseOver);
			intelligenceIcon.addEventListener(MouseEvent.MOUSE_OUT, tipOnMouseOut);
			//智力数字
			intelligenceNumText = new TextField();
			intelligenceNumText.selectable = false;
        	intelligenceNumText.autoSize = TextFieldAutoSize.LEFT;
			intelligenceNumText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			intelligenceNumText.text = animalInfo.intelligence.toString();
			intelligenceNumText.x = intelligenceIcon.x + intelligenceIcon.width + 5;
			intelligenceNumText.y = intelligenceText.y;
			addChild(intelligenceNumText);
			intelligenceNumText.addEventListener(MouseEvent.MOUSE_OVER, onIntelligenceNumTextMouseOver);
			intelligenceNumText.addEventListener(MouseEvent.MOUSE_OUT, onTipOfNumMouseOut);
			//加技能按钮
			if (animalInfo.skillPoint > 0 && PlayerInfoHelper.getInstance().userId == animalInfo.ownerId)
			{
				plusButton = new PlusButton(plusButtons.length, animalConfig.intelligencePerSkillPoint, "智力");
				plusButton.width = 10;
				plusButton.height = 10;
				plusButton.x = intelligenceNumText.x + intelligenceNumText.width + 10;
				plusButton.y = intelligenceIcon.y + (intelligenceIcon.height - plusButton.height) / 2;
				addChild(plusButton);
				plusButtons.push(plusButton);
				plusButton.addEventListener(MouseEvent.CLICK, onPlusButtonClick);
			}
			
			//速度文字
			var speedText:TextField = new TextField();
			speedText.selectable = false;
        	speedText.autoSize = TextFieldAutoSize.LEFT;
			speedText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			speedText.text = "速度";
			speedText.x = intelligenceText.x;
			speedText.y = intelligenceText.y + itemGap;
			addChild(speedText);
			//速度图标
			var SpeedIcon:Class = ResourceHelper.getInstance().getClassByName("SpeedIcon");
			speedIcon = new SpeedIcon();
			speedIcon.width = 20;
			speedIcon.height = 20;
			speedIcon.x = intelligenceIcon.x;
			speedIcon.y = intelligenceIcon.y + itemGap;
			addChild(speedIcon);
			speedIcon.addEventListener(MouseEvent.MOUSE_OVER, speedIconOnMouseOver);
			speedIcon.addEventListener(MouseEvent.MOUSE_OUT, tipOnMouseOut);
			//速度数字
			speedNumText = new TextField();
			speedNumText.selectable = false;
        	speedNumText.autoSize = TextFieldAutoSize.LEFT;
			speedNumText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			speedNumText.text = animalInfo.speed.toString();
			speedNumText.x = intelligenceNumText.x;
			speedNumText.y = intelligenceNumText.y + itemGap;
			addChild(speedNumText);
			speedNumText.addEventListener(MouseEvent.MOUSE_OVER, onSpeedNumTextMouseOver);
			speedNumText.addEventListener(MouseEvent.MOUSE_OUT, onTipOfNumMouseOut);
			//加技能按钮
			if (animalInfo.skillPoint > 0 && PlayerInfoHelper.getInstance().userId == animalInfo.ownerId)
			{
				plusButton = new PlusButton(plusButtons.length, animalConfig.speedPerSkillPoint, "速度");
				plusButton.width = 10;
				plusButton.height = 10;
				plusButton.x = speedNumText.x + speedNumText.width + 10;
				plusButton.y = speedIcon.y + (speedIcon.height - plusButton.height) / 2;
				addChild(plusButton);
				plusButtons.push(plusButton);
				plusButton.addEventListener(MouseEvent.CLICK, onPlusButtonClick);
			}
			
			//装备文字
			var equipText:TextField = new TextField();
			equipText.selectable = false;
        	equipText.autoSize = TextFieldAutoSize.LEFT;
			equipText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			equipText.text = "装备";
			equipText.x = speedText.x;
			equipText.y = speedText.y + itemGap;
			addChild(equipText);
			//装备图标
			var startX:int = equipText.x + equipText.width + 8;
			var startY:int = equipText.y + 5;
			addEquipIcon(animalInfo.equips, startX, startY);

			//原籍
			liveText = new TextField();
			liveText.selectable = false;
        	liveText.autoSize = TextFieldAutoSize.LEFT;
			liveText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			liveText.text = "原籍";
			liveText.x = equipText.x;
			liveText.y = equipText.y + itemGap;
			addChild(liveText);
			
			//原籍数字
			liveNumText = new TextField();
			liveNumText.selectable = false;
        	liveNumText.autoSize = TextFieldAutoSize.LEFT;
			liveNumText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			liveSprite = new Sprite();
			liveSprite.x = speedIcon.x; 
			liveSprite.y = liveText.y;
			liveSprite.addChild(liveNumText);
			addChild(this.liveSprite);
			liveSprite.addEventListener(MouseEvent.MOUSE_OVER, liveSpriteOnMouseOver);
			liveSprite.addEventListener(MouseEvent.MOUSE_OUT, tipOnMouseOut);
			//监狱中的时间
			prisonText = new TextField();
			prisonText.selectable = false;
        	prisonText.autoSize = TextFieldAutoSize.LEFT;
			prisonText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			prisonText.text = "离出狱";
			prisonText.x = equipText.x;
			prisonText.y = equipText.y + itemGap;
			addChild(prisonText);

			//监狱数字
			prisonNumText = new TextField();
			prisonNumText.selectable = false;
        	prisonNumText.autoSize = TextFieldAutoSize.LEFT;
			prisonNumText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			prisonNumText.x = prisonText.x + prisonText.width + 5;
			prisonNumText.y = prisonText.y;
			addChild(prisonNumText);
				
			var timeLeft:int = animalInfo.timeToGetFree - ServerHelper.getInstance().now();
			if (timeLeft < 0)
			{
				liveNumText.text = (animalInfo.ownerId + AddressNavigator.baseLiveNum).toString();
				prisonText.visible = false;
				prisonNumText.visible = false;
			}
			else
			{
				prisonNumText.text = Clock.formatTimeToSecond(timeLeft);
				liveText.visible = false;
				liveNumText.visible = false;
			}
			
			//动作按钮
			var actionPane:ActionPane = new ActionPane(animalInfo);
			actionPane.x = speedText.x;
			actionPane.y = 264;
			
			addChild(actionPane);
			
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			
			timer = new Timer(1000);
			timer.addEventListener(TimerEvent.TIMER, onTick);
			timer.start();
		}

		//加载掉落装备图标
		private function addEquipDropIcon(equips:Object, startX:int, startY:int):void
		{
			var equipCount:int = 0;
			for (var index:String in equips)
			{
				var equipConfig:EquipConfig = Config.objectConfigs[parseInt(index)];
				if (equipConfig.baseIndex == -1)
				{
					var EquipIcon:Class = ResourceHelper.getInstance().getClassByName(equipConfig.iconImage);
					var equipIcon:BasicButton = new BasicButton(EquipIcon, null, 15, equipConfig);
					equipIcon.width = 20;
					equipIcon.height = 20;
					equipIcon.x = startX + 30 * equipCount;
					equipIcon.y = startY;
					addChild(equipIcon);
					equipIcon.addEventListener(MouseEvent.MOUSE_OVER, onEquipDropIconMouseOver);
					equipIcon.addEventListener(MouseEvent.MOUSE_OUT, onEquipIconMouseOut);
					equipCount++;
				}
			}
		}
		
		//加载装备图标:equipDropFlag表示是否是掉落装备项目的图标
		private function addEquipIcon(equips:Object, startX:int, startY:int):void
		{
			//装备图标
			var equipCount:int = 0;
			for (var position:String in equips)
			{
				var equipInfo:EquipInfo = equips[position];
				var equipConfig:EquipConfig = Config.objectConfigs[equipInfo.objectIndex];
				var EquipIcon:Class = ResourceHelper.getInstance().getClassByName(equipConfig.iconImage);
				var equipIcon:BasicButton = new BasicButton(EquipIcon, null, 15, equipInfo);
				equipIcon.width = 20;
				equipIcon.height = 20;
				equipIcon.x = startX + 30 * equipCount;
				equipIcon.y = startY;
				addChild(equipIcon);
				var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
				if (animalInfo.ownerId == PlayerInfoHelper.getInstance().userId)
				{
					equipIcon.addEventListener(MouseEvent.CLICK, onEquipIconClick);
				}
				equipIcon.addEventListener(MouseEvent.MOUSE_OVER, onEquipIconMouseOver);
				equipIcon.addEventListener(MouseEvent.MOUSE_OUT, onEquipIconMouseOut);
				equipCount++;
			}
		}
		
		//掉落装备的信息
		private function onEquipDropIconMouseOver(event:MouseEvent):void
		{
			var equipIcon:BasicButton = event.target.parent as BasicButton;
			var equipConfig:EquipConfig = equipIcon.userData as EquipConfig;
			
			tipOfEquip = new Sprite();
			var roundRec:RoundRec = new RoundRec(150, 260, 0.8, 0x50AF50);
			tipOfEquip.addChild(roundRec);
			//名字
			var nameText:TextField = new TextField();
			nameText.selectable = false;
        	nameText.width = roundRec.width;
        	nameText.autoSize = TextFieldAutoSize.LEFT;
			var nameTexFormat:TextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
			nameTexFormat.leftMargin = 8;
			nameTexFormat.rightMargin = 8;
			nameText.defaultTextFormat = nameTexFormat;
			nameText.text = equipConfig.name;
			nameText.y = 10;
			tipOfEquip.addChild(nameText);
			//具体功能介绍
			var description:TextField = new TextField();
			description.selectable = false;
        	description.autoSize = TextFieldAutoSize.LEFT;
			var textFormat:TextFormat = new TextFormat("微软雅黑", 13, 0x000000);
			textFormat.leftMargin = 8;
			textFormat.rightMargin = 8;
			description.defaultTextFormat = textFormat;
			var animalInfo:VirtualAnimalConfig = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			description.text = "掉落几率:";
			description.y = nameText.y + 20;
			tipOfEquip.addChild(description);
			for (var color:int = 0; color < 4; color++)
			{
				var colorTextFormat:TextFormat;
				if (color == 0)
					colorTextFormat = new TextFormat("微软雅黑", 13, 0x000000);
				else				
					colorTextFormat = new TextFormat("微软雅黑", 13, Config.equipColor1[color], true);
				colorTextFormat.leftMargin = 8;
				colorTextFormat.rightMargin = 8;
				var colorText:TextField = new TextField();
				colorText.autoSize = TextFieldAutoSize.LEFT;
				colorText.y = description.y + 20 * (color + 1);
				colorText.defaultTextFormat = colorTextFormat;
				var dropPossibility:Number = 0;
				if (animalInfo.armsDropPossibility[equipConfig.colorIndexes[color]] != null)
					dropPossibility = animalInfo.armsDropPossibility[equipConfig.colorIndexes[color]]
				if (dropPossibility < 0.0001)
					colorText.text = Config.equipColorName[color] + "  " + (dropPossibility * 100).toFixed(4) + "%";
				else
					colorText.text = Config.equipColorName[color] + "  " + (dropPossibility * 100).toFixed(2) + "%";
				tipOfEquip.addChild(colorText);
			}
			var magicConfig:MagicConfig = Config.magicConfigs[equipConfig.magicIndex];
			var effectText:TextField = new TextField();
			effectText.defaultTextFormat = textFormat;
			effectText.selectable = false;
        	effectText.autoSize = TextFieldAutoSize.LEFT;
        	effectText.width = roundRec.width;
        	effectText.wordWrap = true;
			effectText.text = "魔法: " + magicConfig.name + "\n作用: " + equipConfig.description + "\n整套附加: " + equipConfig.wholeEquipDescription;
			magicConfig = Config.magicConfigs[equipConfig.wholeMagicIndex];
			effectText.appendText("\n整套魔法: " + magicConfig.name);
			effectText.y = description.y + 100;
			tipOfEquip.addChild(effectText);
			
			tipOfEquip.x = equipIcon.x + equipIcon.width + 10;
			tipOfEquip.y = equipIcon.y + equipIcon.height + 10;
			addChild(tipOfEquip);
		}
		
		//装备的信息
		private function onEquipIconMouseOver(event:MouseEvent):void
		{
			var equipIcon:BasicButton = event.target.parent as BasicButton;
			var equip:EquipInfo = equipIcon.userData as EquipInfo;
			var equipConfig:EquipConfig = Config.objectConfigs[equip.objectIndex];
			
			tipOfEquip = new Sprite();
			var roundRec:RoundRec = new RoundRec(140, 210, 0.8, 0x50AF50);
			tipOfEquip.addChild(roundRec);
			
			//单击卸载装备
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			if (animalInfo.ownerId == PlayerInfoHelper.getInstance().userId)
			{
				var helpText:TextField = new TextField();
				helpText.selectable = false;
	        	helpText.width = roundRec.width;
	        	helpText.autoSize = TextFieldAutoSize.CENTER;
				var helptextFormat:TextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
				helptextFormat.leftMargin = 8;
				helptextFormat.rightMargin = 8;
				helptextFormat.color = 0x008000;
				helpText.defaultTextFormat = helptextFormat;
				helpText.text = "单击卸载装备";
				helpText.y = 5;
				tipOfEquip.addChild(helpText);
			}
			
			//名字
			var nameText:TextField = new TextField();
			nameText.selectable = false;
        	nameText.width = roundRec.width;
        	nameText.autoSize = TextFieldAutoSize.LEFT;
			var nametextFormat:TextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
			nametextFormat.leftMargin = 8;
			nametextFormat.rightMargin = 8;
			nameText.defaultTextFormat = nametextFormat;
			if (animalInfo.ownerId == PlayerInfoHelper.getInstance().userId)
			{
				nameText.y = 25;
			}
			else
			{
				nameText.y = 15;
			}
			//具体功能介绍
			var description:TextField = new TextField();
			description.selectable = false;
        	description.autoSize = TextFieldAutoSize.LEFT;
        	description.width = roundRec.width;
        	description.wordWrap = true;
			var textFormat:TextFormat = new TextFormat("微软雅黑", 13, 0x000000);
			textFormat.leftMargin = 8;
			textFormat.rightMargin = 8;
			description.defaultTextFormat = textFormat;
			description.y = nameText.y + 20;
			
			var colorText:TextField = new TextField();
			colorText.selectable = false;
        	colorText.autoSize = TextFieldAutoSize.LEFT;
        	colorText.width = roundRec.width;
        	colorText.wordWrap = true;
			
			var suitEffect:TextField = new TextField();
			suitEffect.selectable = false;
        	suitEffect.autoSize = TextFieldAutoSize.LEFT;
        	suitEffect.width = roundRec.width;
        	suitEffect.wordWrap = true;
			suitEffect.defaultTextFormat = textFormat;
			
			if (equipConfig.durability == -1)
				description.appendText("耐久度: 永久\n");
			else
				description.appendText("耐久度: " + equipConfig.durability + "\n");
			var magicConfig:MagicConfig = Config.magicConfigs[equipConfig.magicIndex];
			description.appendText("魔法: " + magicConfig.name + "\n");
			description.appendText("作用: " + equipConfig.description.toString() + "\n");
			if (equipConfig.color > 0)
			{
				var colorTextFormat:TextFormat = new TextFormat("微软雅黑", 13, Config.equipColor1[equipConfig.color], true);
				colorTextFormat.leftMargin = 8;
				colorTextFormat.rightMargin = 8;
				colorText.y = description.y + description.height - 5;
				colorText.defaultTextFormat = colorTextFormat;
				colorText.text = "品质:" + Config.equipColorName[equipConfig.color] + " " + equipConfig.colorDescribe;
				var colorNameFormat:TextFormat = new TextFormat("微软雅黑", 15, Config.equipColor1[equipConfig.color], true);
				colorNameFormat.leftMargin = 8;
				colorNameFormat.rightMargin = 8;
				nameText.defaultTextFormat = colorNameFormat;
				suitEffect.y = colorText.y + colorText.height - 5 ;
			}
			else
			{
				suitEffect.y = description.y + description.height - 5;
			}
			magicConfig = Config.magicConfigs[equipConfig.wholeMagicIndex];
			suitEffect.text = "整套附加: " + equipConfig.wholeEquipDescription.toString();
			suitEffect.appendText("\n整套魔法: " + magicConfig.name);
			nameText.text = equipConfig.name;
			tipOfEquip.addChild(nameText);
			tipOfEquip.addChild(description);
			tipOfEquip.addChild(colorText);
			tipOfEquip.addChild(suitEffect);
			
			tipOfEquip.x = equipIcon.x + equipIcon.width + 10;
			tipOfEquip.y = equipIcon.y + equipIcon.height + 10;
			addChild(tipOfEquip);
			if (animalInfo.ownerId == PlayerInfoHelper.getInstance().userId)
			{
				Mouse.cursor = "button";
			}
			else
			{
				Mouse.cursor = "auto";
			}
		}
		
		private function onEquipIconMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			if (null !=  tipOfEquip && null != tipOfEquip.parent)
        	{
        		tipOfEquip.parent.removeChild(tipOfEquip);
        	}
		}
		
		private function onEquipIconClick(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			if (animalInfo.ownerId != PlayerInfoHelper.getInstance().userId)
				return;
			var equipIcon:BasicButton = event.target.parent as BasicButton;
			equipToGetOff = equipIcon.userData as EquipInfo;
			var equipConfig:EquipConfig = Config.objectConfigs[equipToGetOff.objectIndex];
			var message:String;
			if (equipToGetOff.durability != -1)
			{
				message = equipConfig.name + " 是非永久物品，\n卸载后将被永久丢弃。是否继续？";
			}
			else
			{
				message = equipConfig.name + " 是永久物品，\n卸载后将被放入包裹。是否继续？";
			}
			var messageBox:MessageBox = new MessageBox(message, 1, true);
			messageBox.x = (BFont.stageWidth - messageBox.width) / 2;
			messageBox.y = (BFont.stageHeight - messageBox.height) / 2;
			SceneContainer.getInstance().currentScene.addChild(messageBox);
			messageBox.buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKClick);
			close();
		}
		
		private function onButtonOKClick(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var equipConfig:EquipConfig = Config.objectConfigs[this.equipToGetOff.objectIndex];
			ServerHelper.getInstance().getOffEquip(animalInfo.id, equipConfig.position, equipToGetOff.id, equipConfig.index, equipConfig.durability, onGetOffEquipComplete); 
		}
		
		private function onGetOffEquipComplete(result:String):void
		{
			if (result == "success")
			{
				if (SceneContainer.getInstance().currentScene is Home)
				{
					var home:Home = SceneContainer.getInstance().currentScene as Home;
					var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
					var myAnimal:AnimalInfo = PlayerInfoHelper.getInstance().animals[me.ownAnimals[0]];
					var homeAnimal:HomeAnimal = home.homeAnimals[myAnimal.id];
					if (homeAnimal != null)
					{
						homeAnimal.refreshEquips();
					}
				}
			}
		}
		
		private function onPlusButtonClick(event:MouseEvent):void
		{
			var plusButton:PlusButton = event.target.parent as PlusButton;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var animalConfig:AnimalConfig = Config.animalConfigs[animalInfo.animalIndex];
			//生命值
			if (plusButton.index == 0)
			{
				ServerHelper.getInstance().balanceSkillPoint(animalInfo.id, -1, animalConfig.healthPointsPerSkillPoint, 0, 0, 0, onPlusComplete);
			}
			//体力值
			else if (plusButton.index == 1)
			{
				ServerHelper.getInstance().balanceSkillPoint(animalInfo.id, -1, 0, animalConfig.vitalityPointsPerSkillPoint, 0, 0, onPlusComplete);
			}
			//智力值
			else if (plusButton.index == 2)
			{
				ServerHelper.getInstance().balanceSkillPoint(animalInfo.id, -1, 0, 0, animalConfig.intelligencePerSkillPoint, 0, onPlusComplete);
			}
			//速度值
			else if (plusButton.index == 3)
			{
				ServerHelper.getInstance().balanceSkillPoint(animalInfo.id, -1, 0, 0, 0, animalConfig.speedPerSkillPoint, onPlusComplete);
			}
		}
		
		public function refresh():void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			bloodNumText.text = animalInfo.currentHealthPoint.toString() + "/" + animalInfo.healthPointMax.toString();
			healthBar.update(animalInfo.currentHealthPoint, animalInfo.healthPointMax);
			vitalityNumText.text = animalInfo.currentVitalityPoint.toString() + "/" + animalInfo.vitalityPointMax.toString();
			vitalityBar.update(animalInfo.currentVitalityPoint, animalInfo.vitalityPointMax);
			intelligenceNumText.text = animalInfo.intelligence.toString();
			speedNumText.text = animalInfo.speed.toString();
			var timeLeft:int = animalInfo.timeToGetFree - ServerHelper.getInstance().now();
			if (timeLeft < 0)
			{
				liveNumText.text = (animalInfo.ownerId + AddressNavigator.baseLiveNum).toString();
				liveText.visible = true;
				liveNumText.visible = true;
				prisonText.visible = false;
				prisonNumText.visible = false;
			}
			else
			{
				prisonNumText.text = Clock.formatTimeToSecond(timeLeft);
				prisonText.visible = true;
				prisonNumText.visible = true;
				liveText.visible = false;
				liveNumText.visible = false;
			}
			if (animalInfo.skillPoint <= 0)
			{
				for (var i:int = 0; i < plusButtons.length; i++)
				{
					plusButtons[i].visible = false;
				}
			}
			this.homeAnimal.setSkillPointIconVisibility();
		}
		
		private function onPlusComplete(result:String):void
		{
			refresh();
		}

		private function onMouseOver(event:MouseEvent):void
		{
			mouseOverFlag = true;
			this.homeAnimal.mouseOverFlag = true;
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			mouseOverFlag = false;
			this.homeAnimal.mouseOverFlag = false;
		}
		
		private function onTick(event:Event):void
		{
			refresh();
			if (mouseOverFlag)
			{
				this.coolDownToClose = this.coolDownToCloseMax;
			}
			else
			{
				if (--this.coolDownToClose < 0)
				{
					close();
				}
			}
		}
		
		public function close():void
		{
			if (this.parent != null)
			{
				this.parent.removeChild(this);
				timer.stop();
				timer.removeEventListener(TimerEvent.TIMER, onTick);
				homeAnimal.animalMessage = null;
			}
		}
		
		//等级
		private function levelSpriteOnMouseOver(event:MouseEvent):void
		{
			var string:String = "等级";
			tip = new BasicMessage(55, 25, string);
			tip.x = levelSprite.x;
			tip.y = levelSprite.y - tip.height;
			addChild(tip);
		}
		
		//经验
		private function expBarOnMouseOver(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var levelConfig:LevelConfig = Config.levelConfigs[animalInfo.level - 1];
			var string:String = "经验距下一等级: " + (levelConfig.experience - animalInfo.experience);
			tip = new BasicMessage(170, 25, string);
			tip.x = this.expBar.x;
			tip.y = this.expBar.y - tip.height;
			addChild(tip);
		}
		
		//血条
		private function healthBarOnMouseOver(event:MouseEvent):void
		{
			var string:String = "生命影响作案胜负";
			tip = new BasicMessage(145, 25, string);
			tip.x = this.healthBar.x;
			tip.y = this.healthBar.y - tip.height;
			addChild(tip);
		}
		
		//血量
		private function onBloodNumTextMouseOver(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var string:String = "基础生命值: " + (animalInfo.currentHealthPoint - animalInfo.healthPointByEquip - animalInfo.healthPointByEquipWhole);
			if (0 != animalInfo.healthPointByEquip)
			{
				string += "\n装备增加: " + animalInfo.healthPointByEquip;
			}
			if (0 != animalInfo.healthPointByEquipWhole)
			{
				string += "\n整套装备增加: " + animalInfo.healthPointByEquipWhole;
			}
		
			tipOfNum = new BasicMessage(145, 75, string);
			tipOfNum.x = this.healthBar.x + this.healthBar.width + 10;
			tipOfNum.y = this.healthBar.y - tipOfNum.height;
			addChild(tipOfNum);
		}
		
		//体力
		private function vitalityBarOnMouseOver(event:MouseEvent):void
		{
			var string:String = "体力决定作案时能否扔动骨头";
			tip = new BasicMessage(220, 25, string);
			tip.x = this.vitalityBar.x;
			tip.y = this.vitalityBar.y - tip.height;
			addChild(tip);
		}
		
		//体力值
		private function onVitalityNumTextMouseOver(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var string:String = "基础体力值: " + (animalInfo.currentVitalityPoint - animalInfo.vitalityPointByEquip - animalInfo.vitalityPointByEquipWhole);
			if (0 != animalInfo.vitalityPointByEquip)
			{
				string += "\n装备增加: " + animalInfo.vitalityPointByEquip;
			}
			if (0 != animalInfo.vitalityPointByEquipWhole)
			{
				string += "\n整套装备增加: " + animalInfo.vitalityPointByEquipWhole;
			}
			tipOfNum = new BasicMessage(145, 75, string);
			tipOfNum.x = this.vitalityBar.x + this.vitalityBar.width + 10;
			tipOfNum.y = this.vitalityBar.y - tipOfNum.height;
			addChild(tipOfNum);
		}
		
		//智力
		private function intelligenceIconOnMouseOver(event:MouseEvent):void
		{
			var string:String = "智力影响偷骨头的数量\n智力影响跑路的费用";
			tip = new BasicMessage(210, 50, string);
			tip.x = this.intelligenceIcon.x;
			tip.y = this.intelligenceIcon.y - tip.height;
			addChild(tip);
		}
		
		//智力值
		private function onIntelligenceNumTextMouseOver(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var string:String = "基础智力值: " + (animalInfo.intelligence - animalInfo.intelligenceByEquip - animalInfo.intelligenceByEquipWhole);
			if (0 != animalInfo.intelligenceByEquip)
			{
				string += "\n装备增加: " + animalInfo.intelligenceByEquip;
			}
			if (0 != animalInfo.intelligenceByEquipWhole)
			{
				string += "\n整套装备增加: " + animalInfo.intelligenceByEquipWhole;
			}
			tipOfNum = new BasicMessage(145, 75, string);
			tipOfNum.x = this.intelligenceIcon.x + this.intelligenceIcon.width + 10;
			tipOfNum.y = this.intelligenceIcon.y - tipOfNum.height;
			addChild(tipOfNum);
		}
		
		//速度
		private function speedIconOnMouseOver(event:MouseEvent):void
		{
			var string:String = "速度影响作案扔骨头的次数";
			tip = new BasicMessage(210, 25, string);
			tip.x = this.speedIcon.x;
			tip.y = this.speedIcon.y - tip.height;
			addChild(tip);
		}
		//速度值
		private function onSpeedNumTextMouseOver(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[homeAnimal.animalId];
			var string:String = "基础速度值: "+ (animalInfo.speed - animalInfo.speedByEquip - animalInfo.speedByEquipWhole);
			if (0 != animalInfo.speedByEquip)
			{
				string += "\n装备增加: " + animalInfo.speedByEquip;
			}
			if (0 != animalInfo.speedByEquipWhole)
			{
				string += "\n整套装备增加: " + animalInfo.speedByEquipWhole;
			}
			tipOfNum = new BasicMessage(145, 75, string);
			tipOfNum.x = this.speedIcon.x + this.speedIcon.width + 10;
			tipOfNum.y = this.speedIcon.y - tipOfNum.height;
			addChild(tipOfNum);
		}
		//原籍
		private function liveSpriteOnMouseOver(event:MouseEvent):void
		{
			var string:String = "门牌号";
			tip = new BasicMessage(70, 25, string);
			tip.x = this.liveSprite.x;
			tip.y = this.liveSprite.y - tip.height;
			addChild(tip);
		}
		
		private function tipOnMouseOut(event:MouseEvent):void
		{
			if (null !=  tip && null != tip.parent)
        	{
        		tip.parent.removeChild(tip);
        	}
		}
		
		private function onTipOfNumMouseOut(event:MouseEvent):void
		{
			if (null !=  tipOfNum && null != tipOfNum.parent)
        	{
        		tipOfNum.parent.removeChild(tipOfNum);
        	}
		}
		
	}
}